#include <ctype.h>
#include <time.h>
#include "defs.h"
+#include "cet.h"
+#include "cet_util.h"
#define TRUE 1
#define FALSE 0
//
// Please replace this with a much more filled out and correct version if you see
// fit.
-unsigned int ascii_to_unicode_2(char* dst, unsigned int dst_max_length, char* src)
+
+/* 2008/06/24, O.K.: Use CET library for ascii-> unicode 2 converter */
+
+unsigned int ascii_to_unicode_2(char *dst, const int dst_max_length, const char *src)
{
+#if 1
+ short *unicode;
+ int len;
+
+ unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len);
+
+ len += 1; /* include terminating null */
+ len *= 2; /* real size */
+ if (len > dst_max_length) len = dst_max_length;
+ memcpy(dst, unicode, len);
+
+ xfree(unicode);
+
+ return len;
+#else
unsigned int current_src_position = 0;
unsigned int current_dst_position = 0;
unsigned short current_unicode_char;
}
return current_dst_position;
+#endif
}
void write_header()
psp_write_str(const char *str)
{
if (str && *str) {
- const char *cin = str;
- gbint16 *tmp, *res;
- int len = 0;
+ short *unicode;
+ int len;
/* convert UTF-8 string into a unicode sequence */
/* not perfect, but enough for us */
+ unicode = cet_str_any_to_uni(str, global_opts.charset, &len);
+ if (len > MAXPSPSTRINGSIZE) len = MAXPSPSTRINGSIZE;
+ gbfputc((unsigned char)len, psp_file_out);
+ if (len) gbfwrite(unicode, 2, len, psp_file_out);
- res = tmp = xmalloc(strlen(str) << 1);
- while (*cin) {
- int bytes, value;
-
- if (cet_utf8_to_ucs4(cin, &bytes, &value) != CET_SUCCESS)
- value = CET_NOT_CONVERTABLE_DEFAULT;
- *tmp++ = value;
- cin += bytes;
- len++;
- if (len == (MAXPSPSTRINGSIZE >> 1)) break;
- }
- gbfputc(len, psp_file_out);
- tmp = res;
- while (len--)
- /* ! we need LE values, don't use gbfwrite ! */
- gbfputint16(*tmp++, psp_file_out);
- xfree(res);
+ xfree(unicode);
}
else
gbfputc(0, psp_file_out);